package com.zzhrtech.wgzx_cityzen;

import android.support.annotation.StringRes;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;

import com.zzhrtech.wgzx_cityzen.utils.ACache;

/**
 * Created by renxiangpeng on 16/7/4.
 */
public class BaseActivity extends AppCompatActivity implements Constans {

    protected Toolbar toolbar;
    ACache mcache;

    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        initToolBar();
    }

    protected void initToolBar() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        if (toolbar != null) {
            this.setSupportActionBar(this.toolbar);
            this.toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    BaseActivity.this.finish();
                }
            });
        }
    }

    protected void setTitle(String title) {
        ActionBar actionBar = this.getSupportActionBar();
        if (actionBar != null) {
            actionBar.setTitle(title);
        }
    }

    //根据id弹出toast
    public void showToast(int resId) {
        showToast(getString(resId));
    }
    //根据文字弹出toast
    public void showToast(String msg) {
        if (!isFinishing()) {

            Toast.makeText(this,msg,Toast.LENGTH_SHORT).show();
//            Snackbar.make(view,msg,Snackbar.LENGTH_SHORT).show();
        }
    }

    public void setTitle(@StringRes int resId) {
        this.setTitle(this.getString(resId));
    }


    public ACache getCache(){
        if (mcache == null) {
            mcache = ACache.get(this);
        }
        return mcache;
    }

}
